﻿using QLNH_BUS_WS.QLNH_DAL_WS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNH_BUS_WS
{
    public class OrderBUS
    {
        public OrderDetailDTO[] GetAllOrderForChef()
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            OrderDetailDTO[] temp = ws.GetAllOrderDetail();

            var result = from o in temp
                       where( o.State == State.New || o.State == State.Modified)
                       select o;

            if (result.Count() > 0)
            {
                return result.ToArray<OrderDetailDTO>();
            }
            else
                return null;
        }

        public OrderDetailDTO[] GetAllOrderForWaiter()
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            OrderDetailDTO[] temp = ws.GetAllOrderDetail();

            var result = from o in temp
                         where (o.State == State.Modified || o.State == State.New || o.State == State.ReadyToServe)
                         select o;
            if (result.Count() > 0)
            {
                return result.ToArray<OrderDetailDTO>();
            }
            else
            {
                return null;
            }
        }

        public OrderDetailDTO[] GetAllOrderForCashier()
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            OrderDetailDTO[] temp = ws.GetAllOrderDetail();

            var result = from o in temp
                         where o.State == State.Served
                         select o;
            if (result.Count() > 0)
            {
                return result.ToArray<OrderDetailDTO>();
            }
            else
            {
                return null;
            }
        }

        public OrderDetailDTO GetOrder(int orderNo)
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            return ws.GetOrder(orderNo);
        }

        public int GenerateOrderNo()
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            return ws.GenerateOrderNo();
        }

        public void AddOrder(OrderDetailDTO order)
        {
            QLNH_DAL_WebServiceSoapClient ws = new QLNH_DAL_WebServiceSoapClient();
            ws.AddOrder(order);
        }

        public void DeleteOrder(int orderNo)
        {
            new QLNH_DAL_WebServiceSoapClient().DeleteOrder(orderNo);    
        }

        public void UpdateOrder(OrderDetailDTO order)
        {
            new QLNH_DAL_WebServiceSoapClient().UpdateOrder(order);
        }

        public void UpdateOrderState(int orderNo, State state)
        {
            new QLNH_DAL_WebServiceSoapClient().UpdateOrderState(orderNo, state);
        }
    }
}